Skip to content

Interpolate into a Boundary Quadrature space on a quadrilateral - #5323

Open
pbrubeck wants to merge 13 commits into
mainfrom
pbrubeck/tensor-facet-quadrature
Open

pbrubeck wants to merge 13 commits into
mainfrom
pbrubeck/tensor-facet-quadrature

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Support interpolation into Boundary Quadrature spaces on quadrilaterals. FIAT supplies the dual evaluation for each facet direction of the tensor-product cell. FIAT #274

When an interpolation appears inside a form, TSFC now includes its target element when inferring the quadrature rule.

  Infer the quadrature rule from:
    arguments, coordinates, coefficients
+   elements of base form operators in the integrand

On a hexahedron, TSFC replaces the quadrature point indices of a facet integral with indices permuted by the facet orientation. An axis with a single point now keeps the fixed index 0, because the only permutation of one point is the identity. Before this change, a Boundary Quadrature coefficient with one point per axis left Delta(q, 0) after its singleton sum was unrolled, and the permuted q kept that Delta from folding before code generation.

 for each reference axis of the facet rule
+  if the axis has a single point
+    use the index 0
   permute the point index by the facet orientation

The regression tests check scalar, vector, and tensor interpolation on triangles and quadrilaterals. They verify that both Function.interpolate and interpolate inside a form reproduce the expression at the exterior and interior facet quadrature points. A TSFC test compiles f*u*ds and Interpolate(u, V)*u*ds on quadrilaterals and hexahedra, with V a Boundary Quadrature space of degree 1 or 2.

Evidence

  • Before — The original quadrilateral interpolation cases raised NotImplementedError: How to tabulate TensorProductElement on FacetPointSet? with the base FIAT revision. With both repositories at their base revisions, f*u*ds on a hexahedron raised AssertionError: cannot generate expression from <class 'gem.gem.Delta'> at degree 1 and reported 0 flops at degree 2.
  • After — With FIAT at db5a42ae, all 405 TSFC tests passed. The new hexahedron cases in test_boundary_quadrature_in_facet_integral fail without the fix. test_quadrature.py and the eight test files with hexahedral facet integrals passed at 1 to 8 MPI ranks. Quadrilateral flop counts did not change. On a perturbed hexahedral mesh, f*u*ds, Interpolate(g, Q)*u*ds, and their dS counterparts matched g*u*ds(degree=deg) to 1e-14 at degrees 1–3. Firedrake still rejects Boundary Quadrature spaces on hexahedral meshes, so this check bypassed check_element in a script. flake8 passed on the changed files. FIAT #274

Merge Danger

Door — Two-way. The Firedrake changes can be reverted independently.

Blast radius — Assembly. The change affects quadrature inference for integrands that contain base form operators, and the point indices of every facet integral on a hexahedron whose rule has an axis with a single point.

Merge FIAT #274 first, then drop the temporary CI install step for its branch.

AI assistance from Claude Code and OpenAI Codex.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o

pbrubeck and others added 6 commits July 29, 2026 11:32
…ient

compile_expression_dual_evaluation contracts the dual evaluation against
the dual coefficient with an IndexSum over the basis indices when the dual
argument is a Cofunction.  When the target element has a block-structured
dual basis (e.g. a RestrictedElement, whose dual evaluation is a
gem.Concatenate), this hid the concatenation index from the subsequent
unconcatenate() call, which can only split along indices that are still
free in the assignment.

Resolve the concatenation of the dual basis before the basis indices are
summed over, following the same pattern already used for coefficient
evaluation in tsfc.fem.  This makes matrix-free adjoint interpolation
(MatMultTranspose of a two-form Interpolate) work for restricted elements.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
EnrichedElement has no dual basis without it, so interpolating into the
facet space of a hexahedron raises NotImplementedError, and gem cannot
unconcatenate a dual basis whose blocks have already been contracted with
a Cofunction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
compile_expression_dual_evaluation carried a TODO to apply the GEM
optimisations that assembly applies.  Apply one of them: contract each
assignment once unconcatenate has split the Concatenate nodes.

This matters for H(div) and H(curl).  Those elements are a sum of blocks,
each mapping into one vector component, and with firedrakeproject/fiat#270
each block selects its component with a Delta.  Before unconcatenation the
blocks are branches of a Concatenate, so the Deltas never meet; afterwards
each pair of blocks is its own assignment, the Deltas multiply, and delta
elimination cancels every pair mapping to different components.

Coarse to fine interpolation, kernel temporaries and wall clock:

    NCF 1->4  832K -> 68K   3.07x faster
    NCE 1->4  307K -> 110K  2.23x faster
    NCE 1->3  131K -> 61K   2.23x faster

Form assembly does not go through this function and is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Apply to dual evaluation the zero handling assembly already does.

Fold zero-valued Literals into symbolic Zero before anything else, so the
algebraic identities built into gem (Product(_, Zero) -> Zero, and so on)
can propagate them and the later steps can prune what they reach.

Then drop any pair whose expression has collapsed to Zero once the blocks
are contracted: a cross-component block that a Delta has just cancelled is
a real zero contribution rather than one merely absent from the sum, and it
must not reach codegen as a temporary.

Emit a Zero temporary as a zero-filled read-only array when one does reach
loopy, as gem.Zero carries no .array for the Constant branch to use.
Run the quadrature element tests on a quadrilateral mesh as well as a
triangular one, and check that interpolation into a facet quadrature space
reproduces the expression at the points and gives both cells sharing a
facet the same values there.

Scalar, vector and tensor valued spaces each take a different path through
dual evaluation, so cover all three.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Point the existing FIAT install step at pbrubeck/tensor-facet-quadrature,
which is pbrubeck/fix/dual-enriched plus the facet quadrature work.  A
Boundary Quadrature space on a quadrilateral cannot be interpolated into
without it: the dual basis names the points of every facet at once, and a
TensorProductElement cannot tabulate on those.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pbrubeck pbrubeck added the base:main Run this PR using a main (dev) build label Aug 4, 2026
Comment thread tsfc/driver.py Resolved
Comment thread tsfc/driver.py Resolved
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread tsfc/loopy.py Resolved
@pbrubeck
pbrubeck force-pushed the pbrubeck/hdivcurl-delta branch from a992610 to 537d1b5 Compare August 18, 2026 22:22
@pbrubeck
pbrubeck force-pushed the pbrubeck/tensor-facet-quadrature branch from 61233e4 to b4efefe Compare September 23, 2026 00:49
@pbrubeck
pbrubeck changed the base branch from pbrubeck/hdivcurl-delta to main November 23, 2026 09:30
Keep the shared TSFC interpolation path. FIAT now returns the facet quadrature basis in the layout used by tabulation. Exercise the quadrature interpolation regressions on one and two MPI ranks.

AI-assisted-by: OpenAI Codex
Use the operators in each integrand when choosing the quadrature rule. Test Boundary Quadrature interpolation in exterior and interior facet integrals.

AI-assisted-by: OpenAI Codex
@pbrubeck pbrubeck added the LLM used An LLM was used in the production of this PR label Nov 23, 2026
@pbrubeck
pbrubeck requested a review from leo-collins November 23, 2026 10:20
pbrubeck and others added 3 commits November 23, 2026 16:32
On a hexahedron the quadrature points of a facet integral are replaced by
orientation-permuted runtime indices. With one point on an axis, a facet
quadrature coefficient leaves Delta(q, 0) after its singleton sum is
unrolled, and the permuted q stops it from folding, so a Delta reached
code generation. The only permutation of a single point is the identity,
so such an axis takes the fixed index 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiE9EeMXhu6p14ShyaFE3o
Apply the facet orientation permutation to the basis tables instead of to the contracted result.
The argument tables are already permuted in the same way.
Interpolated values on Boundary Quadrature elements then need no separate treatment.

AI assistance: OpenAI Codex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base:main Run this PR using a main (dev) build LLM used An LLM was used in the production of this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant